package com.example.administrator.meishi;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.example.administrator.meishi.adapter.ProjectPagerAdapter;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.viewpagerindicator.TabPageIndicator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends FragmentActivity  {
    @ViewInject(R.id.tab_page_indicator)
    private TabPageIndicator tabPageIndicator;
    @ViewInject(R.id.study_viewpager)
    private ViewPager studyViewpager;
    private ProjectPagerAdapter mAdatpter;
    private DrawerLayout draw;
    private ListView lv;
    private List<Map<String, Object>> data;
    private SharedPreferences meishi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        ViewUtils.inject(this);
        mAdatpter = new ProjectPagerAdapter(getSupportFragmentManager());
        studyViewpager.setAdapter(mAdatpter);
        //re.setOnTouchListener();
        tabPageIndicator.setViewPager(studyViewpager);
        draw = (DrawerLayout) findViewById(R.id.draw);
        lv = (ListView) findViewById(R.id.lv);
        data = new ArrayList<>();
        int[] imageID = getimageID();
        String[] stringId = getStringId();
        for (int i=0;i<imageID.length;i++){
            Map<String,Object> map=new HashMap<>();
            map.put("text",stringId[i]);
            map.put("image",imageID[i]);
            data.add(map);
        }


        Toolbar tool = (Toolbar) findViewById(R.id.tool_bar);
        tool.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (draw.isDrawerOpen(Gravity.LEFT)){
                    draw.openDrawer(Gravity.LEFT);
                }else {
                    draw.closeDrawer(Gravity.LEFT);
                }
            }
        });
        SimpleAdapter adapter=new SimpleAdapter(this, data,R.layout.grad_item,new String[]{"text","image"},new int[]{R.id.tvg,R.id.img});
        lv.setAdapter(adapter);
        lv.setFocusable(true);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                switch (position){
                    case 0:
                        Toast.makeText(MainActivity.this,"功能暂未开放",Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                    Intent intent=new Intent(MainActivity.this,Show.class);
                        startActivity(intent);
                        break;
                    case 2:
                        Toast.makeText(MainActivity.this,"功能暂未开放",Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        Toast.makeText(MainActivity.this,"功能暂未开放",Toast.LENGTH_SHORT).show();
                        break;
                    case 4:
                        Toast.makeText(MainActivity.this,"功能暂未开放",Toast.LENGTH_SHORT).show();
                        break;
                    case 5:
                       // Map<String, Set<String>> map = (Map<String, Set<String>>) meishi.getAll();

                        meishi = getSharedPreferences("meishi", MODE_PRIVATE);
                        SharedPreferences.Editor edit = meishi.edit();
                        edit.clear();
                        if (edit.commit()){
                        Toast.makeText(MainActivity.this,"清除成功",Toast.LENGTH_SHORT).show();
                    }


                        break;

                }
            }
        });
    }
    private int[] getimageID(){
        return new int[]{R.mipmap.ic_menu_camera,R.mipmap.ic_menu_gallery,R.mipmap.ic_menu_manage,R.mipmap.ic_menu_send,R.mipmap.ic_menu_share,R.mipmap.ic_menu_slideshow};
    }
    private String[] getStringId(){
        return new String[]{"我的账号","收藏","通用","意见反馈","检测更新","清除下载"};
    }

    public void DL(View view) {
        Intent intent=new Intent(MainActivity.this,Activity2.class);
        startActivity(intent);
    }

    public void ZC(View view) {
        Intent intent=new Intent(MainActivity.this,Activity3.class);
        startActivity(intent);

    }



}